package com.rdgk.newtech.controller;

import com.alibaba.fastjson.JSONObject;
import com.rdgk.newtech.service.StopwordService;
import com.rdgk.newtech.util.CommonUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: msun
 * @description: 停用词相关Controller
 */
@RestController
@RequestMapping("/stopword")
public class StopwordController {

    @Autowired
    private StopwordService StopwordService;

    /**
     * 显示停用词列表
     */
    @RequiresPermissions("article:list")
    @GetMapping("/listStopword")
    public JSONObject listDepartment(HttpServletRequest request) {
        System.out.println(CommonUtil.request2Json(request));
        return StopwordService.listStopword(CommonUtil.request2Json(request));
    }

    /**
     * 搜索停用词列表
     */
    @RequiresPermissions("article:list")
    @GetMapping("/listStopwordBySearch")
    public JSONObject listDepartmentBySearch(HttpServletRequest request) {
        return StopwordService.listStopwordBySearch(CommonUtil.request2Json(request));
    }

    /**
     * 查询停用词是否存在(按停用词名称进行查询)
     */
    @RequiresPermissions("article:list")
    @GetMapping("/getStopwordtByName")
    public JSONObject getStopwordtByName(HttpServletRequest request) {
        System.out.println(CommonUtil.request2Json(request));
        return StopwordService.getStopwordCountByName(CommonUtil.request2Json(request));
    }

    /**
     * 新增停用词
     */
    @RequiresPermissions("article:add")
    @PostMapping("/addStopword")
    public JSONObject addStopword(@RequestBody JSONObject requestJson) {
        return StopwordService.addStopword(requestJson);
    }

    /**
     * 修改停用词
     */
    @RequiresPermissions("article:update")
    @PostMapping("/updateStopword")
    public JSONObject updateStopword(@RequestBody JSONObject requestJson) {
        System.out.println("requestJson:"+requestJson);
        CommonUtil.hasAllRequired(requestJson, "stopwordId, stopwordName, stopwordMark");
        return StopwordService.updateStopword(requestJson);
    }

    /**
     * 删除停用词
     */
    @RequiresPermissions("article:delete")
    @PostMapping("/deleteStopword")
    public JSONObject deleteStopword(@RequestBody JSONObject requestJson) {
        System.out.println("requestJson:"+requestJson);
        CommonUtil.hasAllRequired(requestJson, "id");
        return StopwordService.deleteStopword(requestJson);
    }

}
